package cn.kgc.model.controller;

import cn.kgc.common.utils.ResultUtils;
import cn.kgc.common.utils.result.Result;
import cn.kgc.model.entity.Model;
import cn.kgc.model.entity.dto.ModelDto;
import cn.kgc.model.entity.req.ModelReq;
import cn.kgc.model.service.ModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 商品型号 前端控制器
 * </p>
 *
 * @author qf
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/api/model")
@Api("商品类型")
public class ModelController {

    private final ModelService modelService;

    public ModelController(ModelService modelService) {
        this.modelService = modelService;
    }

    // 分页带条件查询
    @ApiOperation("搜索")
    @GetMapping("search")
    public Result<Map<String, Object>> search(ModelReq modelReq) {
        return ResultUtils.returnDataSuccess(modelService.search(modelReq));
    }

    @GetMapping("{id}/detail")
    public Result<ModelDto> getModelDetailById(@PathVariable Long id) {
        ModelDto modelDto = modelService.getModelDetailById(id);
        return ResultUtils.returnDataSuccess(modelDto);
    }

    @GetMapping
    public Model getById(Long modelId) {
        return modelService.getById(modelId);
    }

}

